home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #42 (Mar 89) / calc source / DrawGrid.c < prev    next >
C/C++ Source or Header  |  1988-12-09  |  1KB  |  47 lines

  1. #include <ListMgr.h>
  2. #include <WindowMgr.h>
  3. #include <MacTypes.h>
  4. #include <QuickDraw.h>
  5.  
  6. #include "MacCalc.h"
  7. #include "SheetHndlg.h"
  8.  
  9. int DrawGrid( win_ptr )
  10. WindowPtr win_ptr ;
  11. {
  12.     GrafPtr tmp_port ;
  13.     Rect win_rect ;
  14.     int bottom ;
  15.     int right ;
  16.     int num_h_lines ;
  17.     int num_v_lines ;
  18.     int i, max ;
  19.     
  20.     GetPort( &tmp_port ) ;
  21.     SetPort( win_ptr ) ;
  22.     
  23.     PenNormal( ) ;
  24.     PenPat( gray ) ;
  25.     
  26.     win_rect = win_ptr->portRect ;
  27.     bottom = win_rect.bottom - 15 ;
  28.     right = win_rect.right - 15 ;
  29.     num_h_lines = bottom / CELL_HEIGTH ;
  30.     num_v_lines = right / CELL_WIDTH ;
  31.     
  32.     max = ( num_h_lines > num_v_lines ) ? num_h_lines:num_v_lines ;
  33.     
  34.     for( i = 1 ; i <= max ; i++ ) {
  35.         if( i < num_h_lines ) {
  36.             MoveTo( 0, i*CELL_HEIGTH ) ;
  37.             LineTo( right, i*CELL_HEIGTH ) ;
  38.         }
  39.         if( i < num_v_lines ) {
  40.             MoveTo( i*CELL_WIDTH, 0 ) ;
  41.             LineTo( i*CELL_WIDTH, bottom ) ;
  42.         }
  43.     }
  44.     PenNormal( ) ;
  45.     SetPort( tmp_port ) ;
  46.             return ;
  47. }